package com.gxs.tga.poc.domain;

import java.io.Serializable;
import java.util.UUID;

import javax.persistence.*;

import com.gxs.tga.poc.domain.dto.TgaWorksheetDto;


/**
 * The persistent class for the TGA_WORKSHEET database table.
 * 
 */
@Entity
@Table(name="TGA_WORKSHEET")
@NamedQuery(name="TgaWorksheet.findAll", query="SELECT t FROM TgaWorksheet t")
public class TgaWorksheet implements Serializable {
	
	public static final String WORKSHEET_SHELL_ID_COMMS = "commConfig";
	public static final String WORKSHEET_SHELL_ID_SVCS = "serviceConfig"; // translateConfig
	public static final String WORKSHEET_SHELL_ID_TP = "tradingPartnerConfig";
	public static final String WORKSHEET_SHELL_ID_TR = "tradingRelationshipConfig";
	
	public static final String WORKSHEET_STATUS_PENDING = "PENDING";
	public static final String WORKSHEET_STATUS_ACTIVE = "ACTIVE";
	public static final String WORKSHEET_STATUS_STAGED = "STAGED";
	public static final String WORKSHEET_STATUS_SAVED = "SAVED";
	
	public static final String WORKSHEET_TARGET_PSIQA = "PSIQA";
	public static final String WORKSHEET_TARGET_PREPROD = "PREPROD";
	public static final String WORKSHEET_TARGET_PROD = "PROD";
	
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="SHEET_INSTANCE_ID", unique=true, nullable=false, length=36)
	private String sheetInstanceId;

	@Column(name="PARENT_WORKSHEET_ID", length=36)
	private String parentWorksheetId;

	@Lob
	@Column(name="SHEET_DATA_BLOB")
	private byte[] sheetDataBlob;

	@Column(name="SHELL_ID", nullable=false, length=100)
	private String shellId;

	@Column(name="SHEET_ID", nullable=false, length=100)
	private String sheetId;

	@Column(name="SHEET_NAME", nullable=false, length=200)
	private String sheetName;

	@Column(name="STATUS_COLLECTED", length=10)
	private String statusCollected = "PENDING";

	@Column(name="STATUS_PREPROD", length=10)
	private String statusPreprod = "PENDING";

	@Column(name="STATUS_PROD", length=10)
	private String statusProd = "PENDING";

	@Column(name="STATUS_PSIQA", length=10)
	private String statusPsiqa = "PENDING";

	//bi-directional many-to-one association to TgaSolution
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="SOLUTION_ID", nullable=false)
	private TgaSolution tgaSolution;

	public TgaWorksheet() {
	}

	public TgaWorksheet(TgaWorksheetDto dto, TgaSolution solution, boolean initializeData, boolean generateId)
	{
		this.parentWorksheetId = dto.getParentWorksheetId();
		if(initializeData || dto.getSheetDataBlob() == null)
			this.sheetDataBlob = null;
		else
			this.sheetDataBlob = dto.getSheetDataBlob().toJSONString().getBytes();
		this.sheetId = dto.getSheetId();
		if(generateId)
			this.sheetInstanceId = UUID.randomUUID().toString();
		else
			this.sheetInstanceId = dto.getSheetInstanceId();
		this.sheetName = dto.getSheetName();
		this.shellId = dto.getShellId();
		this.statusCollected = dto.getStatusCollected();
		this.statusPreprod = dto.getStatusPreprod();
		this.statusProd = dto.getStatusProd();
		this.statusPsiqa = dto.getStatusPsiqa();
		
		this.tgaSolution = solution;
		
	}

	public String getSheetInstanceId() {
		return this.sheetInstanceId;
	}

	public void setSheetInstanceId(String sheetInstanceId) {
		this.sheetInstanceId = sheetInstanceId;
	}

	public String getParentWorksheetId() {
		return this.parentWorksheetId;
	}

	public void setParentWorksheetId(String parentWorksheetId) {
		this.parentWorksheetId = parentWorksheetId;
	}

	public byte[] getSheetDataBlob() {
		return this.sheetDataBlob;
	}

	public void setSheetDataBlob(byte[] sheetDataBlob) {
		this.sheetDataBlob = sheetDataBlob;
	}

	public String getSheetId() {
		return this.sheetId;
	}

	public void setSheetId(String sheetId) {
		this.sheetId = sheetId;
	}

	public String getSheetName() {
		return this.sheetName;
	}

	public void setSheetName(String sheetName) {
		this.sheetName = sheetName;
	}

	public String getStatusCollected() {
		return this.statusCollected;
	}

	public void setStatusCollected(String statusCollected) {
		this.statusCollected = statusCollected;
	}

	public String getStatusPreprod() {
		return this.statusPreprod;
	}

	public void setStatusPreprod(String statusPreprod) {
		this.statusPreprod = statusPreprod;
	}

	public String getStatusProd() {
		return this.statusProd;
	}

	public void setStatusProd(String statusProd) {
		this.statusProd = statusProd;
	}

	public String getStatusPsiqa() {
		return this.statusPsiqa;
	}

	public void setStatusPsiqa(String statusPsiqa) {
		this.statusPsiqa = statusPsiqa;
	}

	public TgaSolution getTgaSolution() {
		return this.tgaSolution;
	}

	public void setTgaSolution(TgaSolution tgaSolution) {
		this.tgaSolution = tgaSolution;
	}

	public String getShellId()
	{
		return shellId;
	}

	public void setShellId(String shellId)
	{
		this.shellId = shellId;
	}
	

}